import { ElLoading } from 'element-plus';

let loadingInstance: any = null;
export const loadingInfo = {
  mounted(el: HTMLElement, binding: any) {
    loadingInstance = ElLoading.service({
      target: el,
      ...binding.value,
    });
  },
  updated(el: HTMLElement, binding: any) {
    if (binding.value !== binding.oldValue) {
      if (binding.value) {
        loadingInstance = ElLoading.service({
          target: el,
          ...binding.value,
        });
      } else {
        loadingInstance.close();
      }
    }
  },
  unmounted() {
    if (loadingInstance) {
      loadingInstance.close();
    }
  },
};
